import React from 'react';

import Pagination from '@/components/Pagination';

import SummaryTable from '@/components/SummaryTable';

/**
 * 表格控件
 * @param columns
 * @param dataSource
 * @param tablePageChange
 * @param pagination
 * @returns {JSX.Element}
 * @constructor
 */
const TableWrapper = ({ columns, dataSource, summaryFields, pagination, dispatch, DISPATCH_TYPE }) => {
    const tablePageChange = ({ current, pageSize }) => {
        dispatch({
            type: DISPATCH_TYPE.tablePageChangeType,
            payload: {
                current,
                pageSize
            }
        });
    };

    return (
        <div>
            <SummaryTable
                bordered
                rowKey="id"
                columns={columns}
                dataSource={dataSource}
                vvSummaryFields={summaryFields}
                pagination={false}
                scroll={{ x: 'max-content' }}
            />
            <Pagination {...pagination} onChange={tablePageChange} />
        </div>
    );
};

export default TableWrapper;
